/*
 * ch58x_uart_init_def.h
 *
 *  Created on: May 14, 2024
 *      Author: Lenovo
 */

#ifndef INCLUDE_CH58X_UART_INIT_DEF_H_
#define INCLUDE_CH58X_UART_INIT_DEF_H_

#define _UART_Init(REMP,UART,TXport, TXpin, RXport, RXpin,BAUD)       \
    do {\
        GPIOPinRemap(REMP, RB_PIN_##UART);\
        GPIO_SetBits(TXport, TXpin);\
        GPIO_ModeCfg(RXport, RXpin, GPIO_ModeIN_PU);\
        GPIO_ModeCfg(TXport, TXpin, GPIO_ModeOut_PP_5mA);\
        UART##_BaudRateCfg(BAUD);\
        R8_##UART##_FCR = (2 << 6) | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN;\
        R8_##UART##_LCR = RB_LCR_WORD_SZ;\
        R8_##UART##_IER = RB_IER_TXD_EN;\
        R8_##UART##_DIV = 1;\
        UART##_ByteTrigCfg(UART_1BYTE_TRIG);\
        UART##_INTCfg(ENABLE, RB_IER_RECV_RDY | RB_IER_LINE_STAT);\
        PFIC_SetPriority(UART##_IRQn, 0x00);\
        PFIC_EnableIRQ(UART##_IRQn);\
        }while (0)

#define  UART_Init(REMP,UART,TXport, TXpin, RXport, RXpin,BAUD)   _UART_Init(REMP,UART,TXport, TXpin, RXport, RXpin,BAUD)
#define  UART_Uninit(UART)  do{ UART##_DefInit();}while(0)

#endif /* INCLUDE_CH58X_UART_INIT_DEF_H_ */
